package org.wlc.demov1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author 王立朝
 * @date 2022/5/11
 * @description: 基础电商推广服务
 * 1、生成最优价商品海报
 * 2、海报含商品推广邀请码
 */
public abstract class NetMall {
    protected Logger logger = LoggerFactory.getLogger(NetMall.class);
    /**
     * 用户ID
     */

    String uId;
    /**
     * 用户密码
     */
    String uPwd;

    public NetMall(String uId, String uPwd) {
        this.uId = uId;
        this.uPwd = uPwd;
    }

    /**
     * 定义可被外部访问的方法generateGoodsPoster，用于生成商品推广海报
     *
     * @param skuUrl 商品地址(京东、淘宝、当当)
     * @return 海报图片base64位信息
     */
    public String generateGoodsPoster(String skuUrl) {
        // 1. 验证登录
        if (!login(uId, uPwd)) {
            return null;
        }
        // 2. 爬虫商品
        Map<String, String> reptile = reptile(skuUrl);
        // 3. 组装海报
        return createBase64(reptile);
    }

    /**
     * 组装海报
     *
     * @param reptile
     * @return
     */
    protected abstract String createBase64(Map<String, String> reptile);

    /**
     * 爬取商品
     *
     * @param skuUrl
     * @return
     */
    protected abstract Map<String, String> reptile(String skuUrl);

    /**
     * 模拟登录
     *
     * @param uId
     * @param uPwd
     * @return
     */
    protected abstract boolean login(String uId, String uPwd);
}
